import * as React from "react";
import * as qs from "query-string";
import {
  Route,
  Redirect,
  RouteProps,
  withRouter,
  RouteComponentProps
} from "react-router-dom";

// export interface props {
//   path: string;
//   exact: boolean;
//   strict: boolean;
//   component: React.ComponentType;
// }

export type PathParamsType = {
  // type whatever you expect in the this.props.match.params.*
};
export type PropsType = RouteComponentProps<PathParamsType> & {
  // your props here
  path: string;
  exact?: boolean;
  strict?: boolean;
  component: React.ComponentType;
  meta?: any;
};
export class PriteRouter extends React.Component<PropsType> {
  componentWillMount() {
    
  }
  render() {
    const {
      component: Component,
      path: path,
      exact: exact,
      strict: strict,
      meta: meta
    } = this.props;
    console.log(this.props);
    const { search } = this.props.location;
    this.props.location.state = qs.parse(search);
    // console.log("这里是自定义的路由组件+render");
    // console.log("这里是自定义的路由组件+path:" + path);
    return (
      <Route
        {...this.props}
        path={path}
        exact={exact}
        strict={strict}
        meta={meta}
        render={(props: any) => <Component {...props} meta={meta} />}
      />
    );
  }
}
export default withRouter(PriteRouter);
